import math

import tensorflow.keras as keras
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import tensorflow as tf
from sklearn.model_selection import train_test_split
from tensorflow.keras.regularizers import l2
from sklearn.metrics import mean_absolute_error,make_scorer
from sklearn.metrics import mean_squared_error
from sklearn.metrics import mean_absolute_error
from sklearn.metrics import mean_absolute_percentage_error, adjusted_rand_score

from src.python.util.getResoures import getData


def run():
    # 获取数据
    x_train, x_test, y_train, y_test = getData()
    # 定义MLP多层感知器人工神经网络回归预测模型
    model = keras.Sequential([
        keras.layers.Dense(
            input_shape=(60,)
            , kernel_initializer='he_normal'
            , units=20
        ),
        keras.layers.BatchNormalization(),
        keras.layers.Activation('relu'),
        keras.layers.Dense(20, kernel_initializer='he_normal'),
        keras.layers.Activation('relu'),
        keras.layers.Dense(units=2)
    ])
    # 模型编写
    model.compile(loss='mse', optimizer='adam')
    # 训练
    print("------------------------------------------- MLP多层感知器人工神经网络回归预测模型：-------------------------------------------")
    model.fit(x_train,y_train,epochs=6666,verbose=0)
    # 用训练好的模型预测测试集
    y_pre = model.predict(x_test)
    # 评估分数
    mae = mean_absolute_error(y_pred=y_pre, y_true=y_test)
    print("平均绝对误差MAE:", mae)
    mse = mean_squared_error(y_pred=y_pre, y_true=y_test)
    print("均方根误差RMSE:", math.sqrt(mse))
    print("均方误差MSE:", mse)
    mape = mean_absolute_percentage_error(y_pred=y_pre, y_true=y_test)
    print("平均绝对百分比误差MAPE:", mape)


if __name__ == "__main__":
    run()